package com.tuomaxu.pojo;

import com.tuomaxu.servlet.HttpServlet;

import java.util.Map;

public class Mapper {
    private Map<String,Map<String,HttpServlet>> map;

    public Mapper(Map<String, Map<String, HttpServlet>> map) {
        this.map = map;
    }

    public HttpServlet getServletByUrl(String url){
        // url:/demo1/lagou
        String[] split = url.split("/");
        if(split.length != 3){
            return null;
        }
        String contextName = "/"+split[1];
        String servletName = "/"+split[2];

        Map<String, HttpServlet> contextMap = map.get(contextName);
        if(contextMap == null){
            return null;
        }

        return contextMap.get(servletName);
    }

}
